package skymeteo.server.app


import org.slf4j.LoggerFactory
import zeus.api.cluster._
import java.util.TimeZone
import zeus.api.Version
import zeus.api.management.ManagementService
import ProcessorMain

/**
 * 主服务
 */
object SkymProcessorProxy extends ZeusServiceApp  with ClusterAuthorize {
  TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"))
  val logger = LoggerFactory.getLogger("skymeteo.server.app")
  Service.currentService = SkymProcessorProxy

  //服务
  def serviceVersion = Version(1, 1, 0)

  def serviceName = "grib2handler"

  appName = "SkymProcessor"
  //自动更新升级标识，默认为false，如果子类覆盖为true将在UpdateManagement中注册相应监听器
  override protected def autoUpdate = true

  val port = -1

  def doStart() = {
    ProcessorMain.init()
  }

  def doStop() = {
    ProcessorMain.destroy()
  }



  override protected def getLinkStatus() {
    super.getLinkStatus()
  }

  def getServiceType = Service.TYPE_SERVICE_CLUSTER

  def isConfigCluster = true

  //系统服务名，用于外部Agent起停服务
  def getSystemServiceName() = "grib2handler"

  def close() = {
    if (isStarted()) stop()
    ServiceCluster.close()
    sys.exit()
  }

  ManagementService.provideService(serviceName)
  ServiceCluster.initCluster(serviceName, serviceListener)
  //自动启动
  start()
}